package friends;

import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class OneShareFriendsMapper extends Mapper<LongWritable, Text, Text, Text>{
    @Override
    protected void map(LongWritable key,
                       Text value,
                       Context context) throws IOException, InterruptedException {
        //转换String
        String line = value.toString();
        //分割数据
        String[] fields = line.split(":");
        //person在前，friends在后
        String person = fields[0];
        String[] friends = fields[1].split(",");

        for (String friend : friends) {
            //friend在前，person在后
            context.write(new Text(friend), new Text(person));
        }
    }
}

